// pages/detail/detail.js
Page({
  data: {
    chapterId:'',
    sourceId:'',
    num:0
  },

  // 接口
   getData:function (e){
    var that=this;
    wx.request({
      url: 'https://m.taoyuewenhua.com/ajax/chapter_content?', 
      data:{
        sourceName:'tf',
        sourceId:this.data.sourceId,
        chapterId:this.data.chapterId?this.data.chapterId:''
      },
      methods:'GET',
      success:function(res){
        console.log(res,'阅读res')
        // console.log(e,'阅读e')
        console.log(that,'阅读that')
        that.setData({
          resdata:res.data,
        })
      },
      fail:function(res){
        console.log('fail');
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options,"ddd")
    this.data.sourceId=options.sourceId
    let {chapterId} =options
    // console.log(chapterId)
    if(chapterId==undefined){ // 这个是 进来之后判断 是否是空 
      console.log('这个是空')
      console.log(wx.getStorageSync('chapterId'))
      const chapterId=wx.getStorageSync('chapterId')
      this.setData({chapterId})
    }else{
      wx.setStorageSync('chapterId',chapterId)
    }
    this.setData({chapterId})
   
    // console.log(this,"nextChapterId")
    this.getData()
  },

   prev:function(e){
    if(this.data.resdata.data.prevChapterId==undefined){
      wx.showToast({
        icon: 'none',
        title: '没有上一章了',
        duration: 1000
      })
    }else{
      this.data.chapterId=this.data.resdata.data.prevChapterId
      console.log( this.data.chapterId,"cccc")
      this.getData(this)
      wx.pageScrollTo({
        scrollTop: 0,
        duration: 0
      })
      this.data.num--;
    }
  },
 next:function(e){
   if(this.data.resdata.data.nextChapterId==undefined){
    wx.showToast({
      icon: 'none',
      title: '没有下一章了',
      duration: 1000
    })
   }else{
    console.log(e,"aaaaa")
    this.data.num++
    this.data.chapterId=this.data.resdata.data.nextChapterId
     this.getData(this)
     wx.pageScrollTo({
    scrollTop: 0,
    duration: 0
    })
   }
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function (options) {
      console.log(options,"onReady")
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})